package cc.yaomm.common.basic.json.convert;

import cc.yaomm.common.basic.base.SuperEnum;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class EnumJsonSerializer extends JsonSerializer<SuperEnum> {
    @Override
    public void serialize(SuperEnum superEnum, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeString(superEnum.toString());
        String fieldName = jsonGenerator.getOutputContext().getCurrentName();
        jsonGenerator.writeStringField(fieldName + "DisplayName", superEnum.getName());
    }
}
